<?php
    
    class CLoader{
	
	function __construct(){
	    
	    
	    
	}
	
	public function load($url,$db_data){
	    
	    global $db_postfix;
	    
	    if ($db_postfix == 'PG'){
		
		$db_data_PG = "host = '$db_data[0]' user = '$db_data[1]' password = '$db_data[2]' dbname = '$db_data[3]'";
	    
		$this->connection = pg_connect($db_data_PG); 
		
		if (!$this->connection) die (pg_last_error());
		
		$sql = pg_query("select * from modules where site = 'frontend' and url = '$url'");
		    
		    if (pg_num_rows($sql) < 1){
			
			$GLOBALS['smarty']->assign('err_msg','Rossz hivatkozást írt be!!!');
			$GLOBALS['smarty']->assign('content_tpl','error_404.tpl');
			
		    }else{
			
			$module = pg_fetch_assoc($sql);
			
			if (file_exists("Controllers/".$module['name'].".php")){
			    
			    include_once("Controllers/".$module['name'].".php");
			    
			    if ($module['template'] != ''){
				
				$GLOBALS['smarty']->assign('content_tpl',$module['template'].'.tpl');
			    
			    }else{
				
				$GLOBALS['smarty']->assign('err_msg','Hova lett a template???');
				$GLOBALS['smarty']->assign('content_tpl','error_404.tpl');
				
			    }
			
			}else{
			    
			    $GLOBALS['smarty']->assign('err_msg','Hova lett a file???');
			    $GLOBALS['smarty']->assign('content_tpl','error_404.tpl');
			    
			}
			
		    }
		    
		if (is_resource($sql)) pg_free_result($sql);
		//mysql_close($connection);
		    
	    }else{
	    
		$connection = mysql_connect($db_data[0],$db_data[1],$db_data[2]);
		
		if (!$connection) die (mysql_error());
		
		$select_db = mysql_selectdb($db_data[3],$connection);
		
		if (!$select_db) die (mysql_error());
		
		$sql = mysql_query("select * from modules where site = 'frontend' and url = '$url'");
		
		if (mysql_num_rows($sql) < 1){
		    
		    $GLOBALS['smarty']->assign('err_msg','Rossz hivatkozást írt be!!!');
		    $GLOBALS['smarty']->assign('content_tpl','error_404.tpl');
		    
		}else{
		    
		    $module = mysql_fetch_assoc($sql);
		    
		    if (file_exists("Controllers/".$module['name'].".php")){
			
			include_once("Controllers/".$module['name'].".php");
			
			if ($module['template'] != ''){
			    
			    $GLOBALS['smarty']->assign('content_tpl',$module['template'].'.tpl');
			
			}else{
			    
			    $GLOBALS['smarty']->assign('err_msg','Hova lett a template???');
			    $GLOBALS['smarty']->assign('content_tpl','error_404.tpl');
			    
			}
		    
		    }else{
			
			$GLOBALS['smarty']->assign('err_msg','Hova lett a file???');
			$GLOBALS['smarty']->assign('content_tpl','error_404.tpl');
			
		    }
		    
		}
		
		if (is_resource($sql)) mysql_free_result($sql);
		//mysql_close($connection);
		
	    }
	
	}
	
	function __destruct(){
	    
	    
	    
	}
	
    }

?>